package com.community.backend.service.impl;

import com.community.backend.mapper.MaintenanceMapper;
import com.community.backend.pojo.Maintenance;
import com.community.backend.pojo.dto.MaintenanceQueryDTO;
import com.community.backend.pojo.vo.MaintenanceQueryVO;
import com.community.backend.service.MaintenanceService;
import com.community.backend.utils.PageResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Slf4j
@Service
public class MaintenanceServiceImpl implements MaintenanceService {
    private final MaintenanceMapper maintenanceMapper;

    public MaintenanceServiceImpl(MaintenanceMapper maintenanceMapper) {
        this.maintenanceMapper = maintenanceMapper;
    }

    @Override
    public PageResult pageQuery(MaintenanceQueryDTO maintenanceQueryDTO) {
        PageHelper.startPage(maintenanceQueryDTO.getCurrentPage(),maintenanceQueryDTO.getPageSize());
        Page<MaintenanceQueryVO> list = maintenanceMapper.pageQuery(maintenanceQueryDTO);
        log.info("查询结果：{}",list);
        return new PageResult(list.getTotal(),list);
    }

    @Override
    public void save(Maintenance maintenance) {
        maintenance.setId(UUID.randomUUID().toString());
        maintenance.setStatus("待分配");
        maintenance.setIsDelete("未删除");
        maintenanceMapper.insert(maintenance);
    }

    @Override
    public void update(Maintenance maintenance) {
        System.out.println("修改报修信息："+maintenance);

        maintenanceMapper.update(maintenance);
    }

    @Override
    public void deleteById(String id) {
        Maintenance maintenance = new Maintenance();
        maintenance.setId(id);
        maintenanceMapper.updateById(maintenance);
    }
}
